package com.jacky.iot.resources;

import org.eclipse.californium.core.CoapResource;
import org.eclipse.californium.core.coap.CoAP;
import org.eclipse.californium.core.server.resources.CoapExchange;

public class PubSubResource extends CoapResource {

    private volatile  String resource = "";

    public PubSubResource() {
        super("pub");
        setObservable(true);
        getAttributes().setTitle("pub-sub Resource");
    }

    @Override
    public void handleGET(CoapExchange exchange) {
        exchange.respond("");
    }

    @Override
    public void handlePOST(CoapExchange exchange) {
        resource = exchange.getRequestText();
        exchange.respond(CoAP.ResponseCode.CHANGED);
        changed();
    }
}
